package com.atguigu.tingshu.user.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/***
 * 初始化账户消息队列
 */
@Configuration
public class UserAccountRabbitConfig {

    /**
     * 初始化用户账户交换机
     * @return
     */
    @Bean
    public Exchange UserAccountExchange(){
        return ExchangeBuilder.directExchange("User_Account_Exchange").build();
    }

    /**
     * 初始化用户账户队列
     * @return
     */
    @Bean
    public Queue UserAccountQueue(){
        return QueueBuilder.durable("UserAccountQueue").build();
    }

    /**
     * 绑定交换机
     * @param UserAccountQueue
     * @param UserAccountExchange
     * @return
     */
    @Bean
    public Binding  UserAccountQueueBindingExchange(@Qualifier("UserAccountQueue")Queue UserAccountQueue,
                                                    @Qualifier("UserAccountExchange")Exchange UserAccountExchange){
        return BindingBuilder.bind(UserAccountQueue).to(UserAccountExchange).with("init_Account").noargs();
    }
}
